package model;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class TodoDate {

	static private SimpleDateFormat dateFormat = null;
	static private SimpleDateFormat timeFormat = null;
	
	static private void setDateFormat() {
		dateFormat = new SimpleDateFormat(
				"yyyy年MM月dd日", 
				Locale.JAPANESE);
	}

	static public String getDateString() {
		if (dateFormat == null) {
			setDateFormat();
		}
		return dateFormat.format(new Date());
	}
	
	static public String getDateString(
			int year, 
			int month, 
			int day) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, day);
		
		if (dateFormat == null) {
			setDateFormat();
		}
		return dateFormat.format(cal.getTime());
	}
	
	static public String getDateString(Todo todo) {
		Calendar cal = Calendar.getInstance();
		cal.set(todo.getYear(), todo.getMonth(), todo.getDay());
		
		if (dateFormat == null) {
			setDateFormat();
		}
		return dateFormat.format(cal.getTime());
	}
	
	static private void setTimeFormat() {
		timeFormat = new SimpleDateFormat(
				"HH時mm分", 
				Locale.JAPANESE);
	}

	static public String getTimeString() {
		if (timeFormat == null) {
			setTimeFormat();
		}
		return timeFormat.format(new Date());
	}
	
	static public String getTimeString(
			int hour, 
			int minute) {
		return String.format("%02d時%02d分", hour, minute);
	}
	
	static public String getTimeString(Todo todo) {
		return String.format(
				"%02d時%02d分", 
				todo.getHour(), 
				todo.getMinute());
	}
}
